﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Toybox.NicoSharp.RSS
{
	using Extensions;
	using Primitives;
	using Utilities;

	[XmlRoot("rss")]
	public class LiveRecentRSS : AbstractLiveRSS
	{

		#region [Static]

		protected const string NAMESPACE_DC = @"http://purl.org/dc/elements/1.1/";

		public static LiveRecentRSS Get(LiveTabType tabType = LiveTabType.All, LiveSortType sortType = LiveSortType.start_time, OrderType orderType = OrderType.Desc, int page = 1)
		{
			string url = NicoUrls.LiveTop + "recent/rss";
			return Get<LiveRecentRSS>(url + "?" + GetQuery(tabType, sortType, orderType, page));
		}

		#endregion [Static]


		#region Public Members

		public Channel channel;

		#endregion Public Members


		#region Protected Methods

		protected static string GetQuery(LiveTabType tabType, LiveSortType sortType, OrderType orderType, int page)
		{
			Dictionary<string, string> query = new Dictionary<string, string>();
			query.Add("tab", tabType.ToSign());
			query.Add("sort", sortType.ToSign());
			query.Add("order", Enum.GetName(typeof(OrderType), orderType).ToLower());
			query.Add("p", page.ToString());

			return Serializer.AndEqualPairSerializer(query);
		}

		#endregion Protected Methods


		#region [SubClass]

		public class Channel : AbstractChannel
		{
			/// <summary>
			/// 放送数
			/// </summary>
			[XmlElement(Namespace = NAMESPACE_LIVE)]
			public int total_count;

			/// <summary>
			/// アイテム
			/// </summary>
			[XmlElement]
			public LiveItem[] item;
		}

		public class LiveItem : Item
		{
			/// <summary>
			/// カテゴリ
			/// </summary>
			[XmlElement]
			public string[] category;

			/// <summary>
			/// サムネイル
			/// </summary>
			[XmlElement(Namespace = NAMESPACE_MEDIA)]
			public Thumbnail thumbnail;

			/// <summary>
			/// 制作者（コミュ＆ID）
			/// </summary>
			[XmlElement(Namespace = NAMESPACE_DC)]
			public string creator;

			/// <summary>
			/// コミュニティ名
			/// </summary>
			[XmlElement(Namespace = NAMESPACE_LIVE)]
			public string community_name;

			/// <summary>
			/// コミュニティID
			/// </summary>
			[XmlElement(Namespace = NAMESPACE_LIVE)]
			public string community_id;

			/// <summary>
			/// コメント数
			/// </summary>
			[XmlElement(Namespace = NAMESPACE_LIVE)]
			public string num_res;

			/// <summary>
			/// 来場者数
			/// </summary>
			[XmlElement(Namespace = NAMESPACE_LIVE)]
			public string view;

			/// <summary>
			/// コミュニティ限定
			/// </summary>
			[XmlElement(Namespace = NAMESPACE_LIVE)]
			public bool member_only;

			/// <summary>
			/// 放送プロバイダ
			/// </summary>
			[XmlElement(Namespace = NAMESPACE_LIVE)]
			public ProviderType type;

			/// <summary>
			/// オーナー名
			/// </summary>
			[XmlElement(Namespace = NAMESPACE_LIVE)]
			public string owner_name;
		}

		#endregion [SubClass]

	}
}
